var e, t = require("../../../../store/index"), a = ((e = t) && e.__esModule, require("../../../../api/log"));

Component({
    externalClasses: [ "x-class" ],
    properties: {
        show: {
            type: Boolean,
            value: !1
        },
        detail: {
            type: Object,
            value: function() {}
        },
        prole: {
            type: String,
            value: ""
        }
    },
    data: {
        popupShow: !1,
        memberInfo: {},
        list: [],
        page: 1,
        finished: !1,
        loading: !1,
        begin: "",
        end: ""
    },
    observers: {
        "show, detail": function() {
            var e = 0 < arguments.length && void 0 !== arguments[0] && arguments[0], t = 1 < arguments.length && void 0 !== arguments[1] ? arguments[1] : {};
            this.setData({
                popupShow: e,
                page: 1,
                list: [],
                finished: !1,
                memberInfo: t
            }), e && this._fetch();
        }
    },
    methods: {
        onPopupClose: function() {
            this.triggerEvent("close");
        },
        onScrollBottom: function() {
            this._fetch();
        },
        onDateChange: function(e) {
            var t = e.currentTarget.dataset.name, a = e.detail.value, i = this.data.begin;
            e = this.data.end;
            if ("begin" === t) {
                if (e && e < a) return void this.setData({
                    begin: a,
                    end: a
                });
            } else if ("end" === t && i && a < i) return void this.setData({
                begin: a,
                end: a
            });
            this.setData(function(e, t, a) {
                return t in e ? Object.defineProperty(e, t, {
                    value: a,
                    enumerable: !0,
                    configurable: !0,
                    writable: !0
                }) : e[t] = a, e;
            }({}, t, a));
        },
        onSearch: function() {
            this.setData({
                page: 1,
                finished: !1,
                list: []
            });
            var e = this.data.begin, t = this.data.end;
            e && t || !e && !t || this.setData({
                begin: "",
                end: ""
            }), this._fetch();
        },
        _fetch: function() {
            var e = this;
            return new Promise(function(t, i) {
                if (e.data.loading || e.data.finished) return t([]);
                var n = (d = e.data.memberInfo).openid, o = d.role, s = e.data.page, r = e.data.begin, d = e.data.end;
                r && (r = r.replace(/-/gi, "/"), r = new Date(r + " 00:00:00").getTime() / 1e3), 
                d && (d = d.replace(/-/gi, "/"), d = new Date(d + " 23:59:59").getTime() / 1e3), 
                e.setData({
                    loading: !0
                }), (0, a.getHistory)({
                    openid: n,
                    role: o,
                    page: s,
                    begin: r,
                    end: d
                }).then(function(a) {
                    var i;
                    a && a.length ? (i = e.data.list, e.setData({
                        list: i.concat(a),
                        page: s + 1,
                        loading: !1,
                        finished: !1
                    })) : 1 == +s ? e.setData({
                        list: [],
                        finished: !0,
                        loading: !1,
                        page: s + 1
                    }) : e.setData({
                        finished: !0,
                        loading: !1,
                        page: s + 1
                    }), t(a);
                }).catch(function() {
                    e.setData({
                        loading: !1
                    }), app.utils.toastText("数据加载失败");
                });
            });
        }
    }
});